package com.example.demonettyclient;

import com.heyi.nettylong.client.NettyClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 */
@RestController
@RequestMapping("/netty/client")
@Slf4j
public class NettyClientController {

	@Autowired
	private NettyClient nettyClient;

	/**
	 * 发送命令socket 长链接 返回发送是否成功
	 * @param msg 命令
	 * @return
	 */
	@PostMapping("/send")
	@ResponseBody
	public Object sendmsg(String msg) throws Exception {

		nettyClient.sendMessage(msg);
		return "ResultUtil.ok()";
	}

	/**
	 * 发送命令socket 长链接 返回发送是否成功
	 * @param msg 命令
	 * @return
	 */
	@PostMapping("/sendback")
	@ResponseBody
	public Object sendmsgback(String msg) throws Exception {

		String m = nettyClient.sendMessageAndReturn(msg, 10);
		log.info("sendback收到数据："+ m);
		return "服务端返回："+m;
	}
}
